﻿using Domain.Entities;
using Domain.IRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Utility;

namespace EFcore.Repositories
{
    /// <summary>
    /// 文章管理仓储实现
    /// </summary>
    public class ConfigRepository : BaseRepository<Config>, IConfigRepository
    {
        public ConfigRepository(JFDbContext dbcontext) : base(dbcontext)
        { }

        /// <summary>
        /// 根据name获取实体
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns></returns>
        public Config GetByName(string configname)
        {
            var model = _dbContext.Set<Config>().FirstOrDefault(i => i.Config_name == configname);
            return model;
        }
        
        
        /// <summary>
        /// 根据ID是否存在，新增或修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddOrUpdate(Config model)
        {
            if (InsertOrUpdate(model, true) != null)
            { return true; }
            else
            { return false; }
        }
        
    }
}
